package com.fysports.web.kit.umeditor;

import com.fysports.web.kit.commons.FileKit;

import java.io.File;


/**
 * Created by konbluesky
 * Date : 14-8-24 下午1:10
 * Project : JdmData_WebServer
 * URL-SIMPLE:/umectr/loadimg/upload-20140824-43811408815131240-jpg
 */
public class DownLoadFileParse {
    private String modulename;
    private String bizuuid;
    private String filename;
    private String suffix;


    public DownLoadFileParse() {
    }


    public DownLoadFileParse(String paramsurl) {
        /**
         * modulename-bizuuid-43811408815131240-jpg
         * 标志：upload
         * 日期：20140802
         * 文件名：43811408815131240
         * 后缀：jpg
         */
        if (paramsurl != null && paramsurl.length() > 0) {
            String[] params = paramsurl.split("-");
            if (params.length != 4) {
                throw new IllegalArgumentException("文件参数不匹配，检查url");
            }
            this.modulename = params[0];
            this.bizuuid = params[1];
            this.filename = params[2];
            this.suffix = params[3];
        }
    }


    public String getModulename() {
        return modulename;
    }


    public void setModulename(String modulename) {
        this.modulename = modulename;
    }


    public String getBizuuid() {
        return bizuuid;
    }


    public void setBizuuid(String bizuuid) {
        this.bizuuid = bizuuid;
    }


    public String getFilename() {
        return filename;
    }


    public void setFilename(String filename) {
        this.filename = filename;
    }


    public String getSuffix() {
        return suffix;
    }


    public void setSuffix(String suffix) {
        this.suffix = suffix;
    }

    /**
     * 获取磁盘中存放路径
     * @return
     */
    public String getDiskUri(){
        return new StringBuilder(FileKit.getDiretory(modulename,bizuuid)).append(File.separator).append(filename).append(".")
                .append(suffix).toString();
    }

    /**
     * 取http用url <br/>
     * 当系统为windows时,需要替换路径(a\b\c  -> a/b/c)<br/>
     * 当系统为linux时,维持原样<br/>
     * @return
     */
    public String getHttpUrl(){
        String sb=getDiskUri();
        return sb.replaceAll("\\\\","/");
    }

//    public static void main(String[] args) {
//        UmeditorHandlerFileUrl uhf=new UmeditorHandlerFileUrl();
//        uhf.setBiaozhi("biaozhi");
//        uhf.setDate(DateTimeKit.format(new Date(),"yyyyMMdd"));
//        uhf.setFilename("filename");
//        uhf.setSuffix("jpg");
//        System.out.println(uhf.toString());
//        System.out.println(uhf.getDiskUri());
//        System.out.println("biaozhi\\20151211\\filename.jpg".replaceAll("\\\\","/"));
//    }
}